package com.acme.bankapp.service.bank;

import java.util.Set;

import com.acme.bankapp.domain.bank.*;

public class BankService {

	public static void addClient(Bank bank, Client client) {
		bank.getClients().add(client);
		for (ClientRegisrationListener listener : bank.getListeners()) {
			listener.onClientAdded(client);
		}
	}

	public static void addAccount(Bank bank, String nameOfClient,
			int... initialValueAndOverDraft) {
		Client wantedClient = null;
		Account sevAcc = new SavingsAccount(initialValueAndOverDraft[0]);
		if (initialValueAndOverDraft.length == 1) {
			Set<Client> clients = bank.getClients();
			for (Client cl : clients) {
				if (cl.getName().equals(nameOfClient)) {
					wantedClient = cl;
				}
			}
			wantedClient.getAccounts().add(sevAcc);
		} else if (initialValueAndOverDraft.length == 2) {
			Account checkAcc = new CheckingAccount(initialValueAndOverDraft[0],
					initialValueAndOverDraft[1]);
			Set<Client> clients = bank.getClients();
			for (Client cl : clients) {
				if (cl.getName().equals(nameOfClient)) {
					wantedClient = cl;
				}
			}
			wantedClient.getAccounts().add(checkAcc);
		} else {
			System.out.println("Wrong format input data");
		}
	}

	public static void printBank(Bank b) {
		Set<Client> cl = b.getClients();
		for (Client client : cl) {
			System.out.println(client.toString() + "\n");
		}
	}
}
